﻿using Microsoft.AspNetCore.Mvc;
using tools.algorithm;

namespace tools.api.Controllers
{
    /// <summary>
    /// RSA 工具操作
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RsaController : ControllerBase
    {
        [HttpGet]
        public IActionResult Encrypt_String(string publicKey, string plainText)
        {
            return Ok(RsaTool.EncryptOfString(publicKey, plainText));
        }

        [HttpGet]
        public IActionResult Decrypt_String(string privateKey, string cipherText)
        {
            return Ok(RsaTool.DecryptOfString(privateKey, cipherText));
        }

        [HttpGet]
        public IActionResult Encrypt_File(string publicKeyPath, string plainText)
        {
            return Ok(RsaTool.EncryptOfFile(publicKeyPath, plainText));
        }

        [HttpGet]
        public IActionResult Decrypt_File(string privateKeyPath, string cipherText)
        {
            return Ok(RsaTool.DecryptOfFile(privateKeyPath, cipherText));
        }
    }
}
